package com.dgshanger.sanhxiaofeisc.mvp.presenter

import android.text.TextUtils
import com.dgshanger.sanhxiaofeisc.mvp.contract.GradeContract
import com.dgshanger.sanhxiaofeisc.mvp.model.GradeModel
import com.xx.baseuilibrary.mvp.BaseMvpPresenter
import com.xx.baseutilslibrary.network.rx.XxBaseHttpObserver
import java.util.*

/**
 * Created by JacobHHH on 2018/4/20.
 */
class GradePresenter : BaseMvpPresenter<GradeContract.Model, GradeContract.View>(), GradeContract.Presenter {


    override fun submitComment(order_sn: String?, comment_score: String?, comment_content: String?
                               , img: MutableList<String>?) {

        if ("0.0"==comment_score){
            getView()?.showToast("请评分")
            return
        }else if (TextUtils.isEmpty(comment_content)&&img!!.isEmpty()){
            getView()?.showToast("评价内容不能为空")
            return
        }

        getModel().submitComment(order_sn,comment_score,comment_content,img,object : XxBaseHttpObserver<Any>(){

            override fun onCompleted(msg: String?, entity: Any?) {
                getView()?.submitCommentSuccess(msg)
            }

            override fun onError(error: String?) {
                getView()?.showToast(error)
            }

            override fun onStart() {
                getView()?.showLoadingDialog("提交中...")
            }

            override fun onFinish() {
               getView()?.dismissLoadingDialog()
            }

        })

    }

    private val mCurrentImageLists = ArrayList<String>()

    override fun imageSelect(newImageLists: MutableList<String>?) {
        if (null == newImageLists || newImageLists.size == 0) {
            return
        }

        mCurrentImageLists.addAll(newImageLists)

        //刷新UI
        if (null != getView()) {
            getView()?.setImageResult(mCurrentImageLists)
        }
    }

    override fun imageDelete(newImageLists: MutableList<String>?) {
        if (null == newImageLists) {
            return
        }
        mCurrentImageLists.clear()
        mCurrentImageLists.addAll(newImageLists)

        if (null != getView()) {
            getView()?.setImageResult(newImageLists)
        }
    }

    override fun createModel(): GradeContract.Model = GradeModel()
}